<template>
	<view class="course_list_container">
		<view class="item" v-for="(item, index) in courseList" :key='index'
			@click="goNav('/me/create/video/edit?courseId='+item.courseId+'&courseDetailsId='+item.courseDetailsId+'&type=1')">
			<view class="pic_title align-center" style="position: relative;">
				<image src='/static/images/index/v_3.png' style="width: 28rpx;height: 28rpx;position: absolute;right: 0;top: 0;"   @click.stop="deleteItem(item.courseDetailsId,index)"></image>
				<image :src='item.titleImg' mode="aspectFill"></image>
				<view class="title_box">
					<view class="name">{{item.courseDetailsName}}</view>
					<!-- <view style="display: flex; align-items: center;">
						<view class="type">{{item.classificationName}}</view>
						<view class="label_text text-ellipsis one-text-ellipsis" style="flex: 1;">{{item.courseLabel}}</view>
					</view> -->
					<view class="label" style="display: flex;align-items: center;">是否收费：
							<view class="choose_radio_box" style="display: flex;align-items: center;">
								<view class="c_item"  @click.stop="updataInfo(item,2)">
									<image src='/static/images/index/choose.png' v-if='item.isPrice==1'></image>
									<image src='/static/images/index/choose_1.png' v-else></image>
									<text>是</text>
								</view>
								<view class="c_item" @click.stop="updataInfo(item,1)">
									<image src='/static/images/index/choose.png' v-if='item.isPrice==2'></image>
									<image src='/static/images/index/choose_1.png' v-else></image>
									<text>否</text>
								</view>
							</view>
					</view>
					
					<view class="label" style="display: flex;align-items: center;">是否推荐：
							<view class="choose_radio_box" style="display: flex;align-items: center;">
								<view class="c_item"  @click.stop="updataInfo(item,3)">
									<image src='/static/images/index/choose.png' v-if='item.good==1'></image>
									<image src='/static/images/index/choose_1.png' v-else></image>
									<text>推荐</text>
								</view>
								<view class="c_item" @click.stop="updataInfo(item,4)">
									<image src='/static/images/index/choose.png' v-if='item.good==2'></image>
									<image src='/static/images/index/choose_1.png' v-else></image>
									<text>不推荐</text>
								</view>
							</view>
					</view>
					
					

					<view class="label">集价格：<text style="color: #FD7885;">¥{{item.price}}</text></view>
					
					<view class="play_video_btn" @click.stop="goNav('/me/create/video/play?videoUrl='+item.videoUrl)">
						<image src='/static/images/index/v_4.png'></image>
						<text>播放视频</text>
					</view>
				</view>
			</view>
			<!-- <view class="btn_box">
				<u-button type="error" size="mini" v-if="item.isPrice==1" @click.stop="updataInfo(item,1)">免费</u-button>
				<u-button type="error" size="mini" v-if="item.isPrice!=1" @click.stop="updataInfo(item,2)">收费</u-button>
				<u-button type="error" size="mini" v-if="item.good == 1" @click.stop="updataInfo(item,3)">不推荐</u-button>
				<u-button type="error" size="mini" v-if="item.good != 1" @click.stop="updataInfo(item,4)">推荐</u-button>
				<u-button type="error" size="mini" @click.stop="deleteItem(item.courseDetailsId,index)">删除</u-button>
				<u-button type="primary" size="mini"
					@click.stop="goNav('/me/create/video/edit?courseId='+item.courseId+'&courseDetailsId='+item.courseDetailsId+'&type=1')">修改</u-button>
				<u-button type="success" size="mini"
					@click.stop="goNav('/me/create/video/play?videoUrl='+item.videoUrl)">播放视频</u-button>

			</view> -->
		</view>

		<view class="footer-btn" style="z-index: 9999;">
			<view class="usermain-btn" @click.stop="goNav('/me/create/video/edit?courseId='+courseId+'&type=0')">新增视频
			</view>
		</view>

		<u-loadmore v-if="courseList.length > 0" :status="status" />
		<empty title="暂无资源" :isShow='false' v-if="courseList.length==0"></empty>
	</view>
</template>

<script>
	import empty from '@/components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				courseList: [],
				status: 'loadmore',
				page: 1,
				limit: 10,
				courseId: null
			}
		},
		onLoad(option) {
			this.courseId = option.courseId
			this.getCourseList()
		},
		onShow() {
			this.getCourseList()
		},
		methods: {
			changePrice(e){
				console.log(e)
			},
			updataInfo(item, indexNo) {
				var data = item;
				if (indexNo == 1) {
					item.isPrice = 2
				}
				if (indexNo == 2) {
					item.isPrice = 1
				}
				if (indexNo == 3) {
					item.good = 2
				}
				if (indexNo == 4) {
					item.good = 1
				}
				var that = this
				this.$u.post("/app/user/updateCourseDetailsByApp", data).then(res => {
					if (res.code === 0) {
						uni.showToast({
							title: '更新成功',
							icon: "none"
						})
						setTimeout(function() {
							that.getCourseList()
						}, 1000)
					} else {
						that.getCourseList()
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				});

			},
			deleteItem(id, index) {
				var that = this
				uni.showModal({
					title: '提示',
					content: '是否确认删除该视频',
					success: function(res) {
						if (res.confirm) {
							that.$u.get("/app/user/deleteCourseDetailsByApp?ids=" + id).then(
								res => {
									if (res.code === 0) {
										that.courseList.splice(index, 1)
										uni.showToast({
											title: '删除成功',
											icon: "none"
										})
									} else if (res.code === -1) {
										uni.showModal({
											title: '温馨提示',
											content: res.msg,
											cancelText: "取消", // 取消按钮的文字
											confirmText: "去商城", // 确认按钮的文字 
											confirmColor: '#8B8FF0',
											success: e => {
												if (e.confirm) {
													uni.navigateTo({
														url: '/me/shop/index'
													});
												}
											}
										});

									} else {
										uni.showToast({
											title: res.msg,
											icon: "none",
											duration: 5000
										})
									}
								});


						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			getCourseList() {

				let data = {
					limit: this.limit,
					page: this.page,
					id: this.courseId
				}

				this.$u.get("/app/user/selectCourseByIdByApp", data).then(
					res => {
						if (res.code === 0) {
							this.pages = res.data.totalPage
							if (this.page < this.pages) {
								this.status = 'loadmore'
							} else {
								this.status = 'nomore'
							}
							if (this.page == 1) {
								this.courseList = res.data.list
							} else {
								this.courseList = [...this.courseList, ...res.data.list]
							}
						} else {
							uni.stopPullDownRefresh();
						}
					});


			},
			goNav(e) {
				uni.navigateTo({
					url: e
				})
			},
		},
		onReachBottom: function() {
			if (this.page < this.pages) {
				this.page += 1
				this.status = 'loading'
				this.getCourseList()

			} else {
				this.status = 'nomore'
			}

		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getCourseList()
		},

	}
</script>

<style>
	page {
		background: #F7F8FF;
	}
</style>
<style scoped lang="scss">
	
	
	.play_video_btn{
		display: flex;
		align-items: center;
		justify-content: center;
		width: 180rpx;
		height: 56rpx;
		background: #373A44;
		border-radius: 10rpx;
		image{
			width: 20rpx !important;
			height: 20rpx !important;
			margin-right: 5rpx !important;
			border-radius: 0 !important;
		}
		text{
			font-weight: 500;
			font-size: 20rpx;
			color: #FFFFFF;
		}
	}
	
	
	.c_item{
		display: flex;
		align-items: center;
		margin-right: 40rpx;
		image{
			width: 29rpx !important;
			height: 28rpx !important;
			margin-right: 13rpx !important;
			border-radius: 0 !important;
		}
		text{
			font-weight: bold;
			font-size: 24rpx;
			color: #333333;
		}
	}
	
	
	
	
	.footer-btn {
		padding-bottom: calc(20rpx + constant(safe-area-inset-bottom));
		padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
		box-sizing: content-box;
		// background-color: #fff;
		position: fixed;
		left: 0;
		bottom: 0;
		width: 750rpx;
		padding-top: 20rpx;
	}

	.footer-btn .usermain-btn {
		color: #FFFFFF;
		background: linear-gradient(90deg, #ff7581, #f8a5af);
		text-align: center;
		width: 686rpx;
		height: 80rpx;
		font-size: 28rpx;
		line-height: 80rpx;
		margin: 0 auto;
		border-radius: 40rpx;
	}



	.course_list_container {
		padding: 20rpx 30rpx;
		padding-bottom: calc(120rpx + constant(safe-area-inset-bottom));
		padding-bottom: calc(120rpx + env(safe-area-inset-bottom));

		.item {
			width: 690rpx;
			background: #FFFFFF;
			border-radius: 10rpx;
			margin-bottom: 20rpx;
			padding: 30rpx 20rpx;
			.pic_title {
				display: flex;

				image {
					width: 200rpx;
					height: 240rpx;
					border-radius: 8rpx;
					margin-right: 12rpx;
					flex-shrink: 0;
				}

				.name {
					display: block;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					width: 500rpx;
					font-weight: bold;
					font-size: 28rpx;
					color: #1A1A1A;
					padding-bottom: 16rpx;
				}

				.label {
					font-weight: 500;
					font-size: 24rpx;
					color: #999999;
					padding-bottom: 16rpx;
					text {
						font-weight: bold;
						font-size: 24rpx;
						color: #333333;
					}
				}

				.type {
					border: 1px solid #8B8FF0;
					color: #8B8FF0;
					margin-right: 4rpx;
					padding-top: 6rpx;
					border-radius: 8rpx;
					font-size: 24rpx;
				}

				.label_text {
					font-weight: 400;
					font-size: 28rpx;
					color: #969696;
					// display:block;
					// white-space:nowrap;
					// overflow:hidden;
					// text-overflow:ellipsis;
					// width: 500rpx;
				}
			}

			.btn_box {
				display: flex;
				margin-top: 20rpx;
				justify-content: flex-end;

				button {
					margin: 0 !important;
					margin-left: 20rpx !important;
				}
			}
		}
	}
</style>